package com.sun.client;

import java.net.InetSocketAddress;

import org.apache.mina.core.RuntimeIoException;
import org.apache.mina.core.future.ConnectFuture;
import org.apache.mina.core.session.IoSession;
import org.apache.mina.transport.socket.SocketConnector;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class VersionClient{

	static final Logger logger = LoggerFactory.getLogger(VersionClient.class);
	
	public  int connect_TimeOut;

    private String host;
    
    private int port;
    
    private SocketConnector connector;
    
    private IoSession session;
    
    public void sentData() throws InterruptedException{
    	for (;;) {
	        try {
	            ConnectFuture future = connector.connect(new InetSocketAddress(host, port));
	            
	            future.awaitUninterruptibly();
	            
	            session = future.getSession();
	            
//	            ConfigRequestBean bean = new ConfigRequestBean();
//	        	
//	        	bean.setSysID("9999");
//	        	bean.setCurrentVersion("xxx");
//	        	session.write(bean);
	            break;
	        } catch (RuntimeIoException e) {
	        	
	            System.err.println("Failed to connect.");
	            
	            e.printStackTrace();
	            
	            Thread.sleep(5000);
	            
	        }
	    }
		
		session.getCloseFuture().awaitUninterruptibly();
		
    	
    }
	public int getConnect_TimeOut() {
		return connect_TimeOut;
	}

	public void setConnect_TimeOut(int connectTimeOut) {
		connect_TimeOut = connectTimeOut;
	}

	public String getHost() {
		return host;
	}

	public void setHost(String host) {
		this.host = host;
	}

	public int getPort() {
		return port;
	}

	public void setPort(int port) {
		this.port = port;
	}
	public SocketConnector getConnector() {
		return connector;
	}
	public void setConnector(SocketConnector connector) {
		this.connector = connector;
	}
	
	
    
    
}
